package BasicKnowledge.Basic.IO;

import java.io.*;

/**
 * @time: 2021/2/2/002 17:38
 * @author: Zhurunhe
 */
public class Demo10 {
    public static void main(String[] args) {
        //testObjOutputStream();//序列化
        testObjInputStream();//反序列化

    }

    private static void testObjInputStream() {
        ObjectInputStream objectInputStream= null;
        try {
            InputStream inputStream=new FileInputStream("G:/obj.txt");
            objectInputStream = new ObjectInputStream(inputStream);
            Object o = objectInputStream.readObject();
            System.out.println(o);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            if(objectInputStream!=null){
                try {
                    objectInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }

    /*private static void testObjOutputStream() {
        PPerson p1=new PPerson("zhangsan",001);

        ObjectOutputStream objectOutputStream= null;
        try {
            OutputStream outputStream=new FileOutputStream("G:/obj.txt");
            objectOutputStream = new ObjectOutputStream(outputStream);
            objectOutputStream.writeObject(p1);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (objectOutputStream!=null){
                try {
                    objectOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }*/

}
